﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections;
using System.IO;
using System.Xml;

namespace CooStationsToolsNew
{
    /// <summary>
    /// ResourceManagerWin.xaml 的交互逻辑
    /// </summary>
    public partial class ResourceManagerWin : Window
    {
        List<UIElement> list = new List<UIElement>();
        List<Grid> list_grid = new List<Grid>();
        string LastText = "";
        ArrayList filelist = new ArrayList();
        ArrayList ParentList = new ArrayList();
        string type = "";
        object obj = null;
        string ImagePath = "";
        string ComputerPath = "";
        int count = 0;
        public ResourceManagerWin(string theType)
        {
            type = theType;
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            GetThePath();
            if (type == "image")
            {
                App.NewRect = "";
                GetImageList(ImagePath,"");
                imgLb.IsSelected = true;
            }
            else if (type == "rectangle")
            {
                App.NewImage = "";
                CreateRectGrid(0);
                upwardBtn.IsEnabled = false;
                rectLb.IsSelected = true;
            }

            initTheSearchList();
        }

        private void initTheSearchList()
        {
            fileSel_cb.Items.Add("全部磁盘");
            fileSel_cb.Items.Add("本地磁盘");
            fileSel_cb.Items.Add("当前目录");
        }
        

        /// <summary>
        /// 获得所有父级列表
        /// </summary>
        /// <param name="path"></param>
        private void GetPathParent(string path)
        {
            DirectoryInfo dr = new DirectoryInfo(path);
            isSel_cb.Items.Add(dr.Name);
            ParentList.Add(dr);
            if (dr.Parent != null)
            {
                GetPathParent(dr.Parent.FullName);
            }
            else
            {
                return;
            }
        
        }

 

        /// <summary>
        /// 得到项目文件中上次的地址
        /// </summary>
        private void GetThePath()
        {
            XmlDocument mydoc = new XmlDocument();
            mydoc.Load(App.appPath + "\\temp\\" + App.proName + ".cfy");
            XmlNode root = mydoc.SelectSingleNode("root");
            XmlNode xn = root.SelectSingleNode("path");
            if (xn != null)
            {
                ImagePath = xn.SelectSingleNode("ImagePath").InnerXml;
                ComputerPath = xn.SelectSingleNode("ComputerPath").InnerXml;
                DirectoryInfo dr = new DirectoryInfo(ImagePath);
                if (!dr.Exists)
                { ImagePath = App.appPath + "\\Contents\\GooPic"; }
                if (ComputerPath == "")
                {
                    ComputerPath = ImagePath;
                }
                DirectoryInfo Cdr = new DirectoryInfo(ComputerPath);
                if (!Cdr.Exists)
                { ComputerPath = ""; }
            }
            else
            {
                ImagePath = App.appPath + "\\Contents\\GooPic";
                ComputerPath = "";
                XmlElement xepath = mydoc.CreateElement("path");
                root.AppendChild(xepath);

                XmlElement xeImagePath = mydoc.CreateElement("ImagePath");
                xeImagePath.InnerXml = ImagePath;
                xepath.AppendChild(xeImagePath);

                XmlElement xeComputerPath = mydoc.CreateElement("ComputerPath");
                xeComputerPath.InnerXml = ComputerPath;
                xepath.AppendChild(xeComputerPath);

            }
            mydoc.Save(App.appPath + "\\temp\\" + App.proName + ".cfy");
        }

        /// <summary>
        /// 保存上次地址
        /// </summary>
        private void SaveThePath()
        {
            XmlDocument mydoc = new XmlDocument();
            mydoc.Load(App.appPath + "\\temp\\" + App.proName + ".cfy");
            XmlNode root = mydoc.SelectSingleNode("root");
            XmlNode xn = root.SelectSingleNode("path");

            if (xn != null)
            {
                xn.SelectSingleNode("ImagePath").InnerXml = ImagePath;
                xn.SelectSingleNode("ComputerPath").InnerXml = ComputerPath;
                
            }
            mydoc.Save(App.appPath + "\\temp\\" + App.proName + ".cfy");
        }

        private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }

        
        private void lbtn_close_Click(object sender, RoutedEventArgs e)
        {
            App.NewRect = null;
            App.NewImage = null;
            SaveThePath();
            this.Close();
        }

        private void CreateRectGrid(int index)
        {
            RowDefinition rowd = new RowDefinition();
            rowd.Height = new GridLength(20.0);
            fileGrid.RowDefinitions.Add(rowd);
            Grid grid = new Grid();
            grid.Tag = "rectangle";
            grid.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(grid_PreviewMouseLeftButtonDown);
            grid.VerticalAlignment = VerticalAlignment.Center;
            grid.HorizontalAlignment = HorizontalAlignment.Left;
            ColumnDefinition cd1 = new ColumnDefinition();
            cd1.Width = new GridLength(20.0);
            grid.ColumnDefinitions.Add(cd1);
            ColumnDefinition cd2 = new ColumnDefinition();
            cd2.Width = new GridLength(221, GridUnitType.Star);
            grid.ColumnDefinitions.Add(cd2);
            Rectangle rect = new Rectangle();
            rect.StrokeThickness = 2;
            rect.Stroke = new SolidColorBrush(Colors.Black);
            rect.Fill = new SolidColorBrush(Colors.Yellow);
            grid.Children.Add(rect);
            Grid.SetRow(rect, 0);
            Grid.SetColumn(rect, 0);
            TextBlock name_tb = new TextBlock();
            name_tb.Text = "矩形";
            name_tb.HorizontalAlignment = HorizontalAlignment.Left;
            name_tb.VerticalAlignment = VerticalAlignment.Center;
            name_tb.TextTrimming = TextTrimming.WordEllipsis;
            grid.Children.Add(name_tb);
            Grid.SetRow(name_tb, 0);
            Grid.SetColumn(name_tb, 1);
            fileGrid.Children.Add(grid);
            Grid.SetRow(grid, index);
            Grid.SetColumn(grid, 0);
            list.Add(rect);
            list.Add(name_tb);
            list.Add(grid);
        }

        /// <summary>
        /// 建立文件列表
        /// </summary>
        /// <param name="index">索引位置</param>
        /// <param name="filename">文件名</param>
        /// <param name="fileCtime">创建时间</param>
        /// <param name="filesize">文件大小</param>
        /// <param name="filepath">文件路径</param>
        /// <param name="filetype">文件类型</param>
        private void CreatFileGrid(int index, string filename, string fileCtime, string filesize, object file, string filetype)
        {
            RowDefinition rowd = new RowDefinition();
            rowd.Height =new GridLength(20.0);
            fileGrid.RowDefinitions.Add(rowd);
            Grid grid = new Grid();
            grid.Tag = file;
          //  grid.Width = 241.0;
            grid.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(grid_PreviewMouseLeftButtonDown);
            grid.VerticalAlignment = VerticalAlignment.Center;
            grid.HorizontalAlignment = HorizontalAlignment.Left;
            ColumnDefinition cd1 = new ColumnDefinition();
            cd1.Width = new GridLength(20.0);
            grid.ColumnDefinitions.Add(cd1);
            ColumnDefinition cd2 = new ColumnDefinition();
            cd2.Width = new GridLength(221, GridUnitType.Star); 
            grid.ColumnDefinitions.Add(cd2);
            Image img = new Image();
            img.Stretch = Stretch.None;
            if (filetype == ".jpg" || filetype == ".JPG")
            {
                img.Source = new BitmapImage(new Uri("pic/rmjpg.png", UriKind.RelativeOrAbsolute));
                img.Width = 16.0;
                img.Height = 17.0;
            }
            else if (filetype == ".png" || filetype == ".PNG")
            {
                img.Source = new BitmapImage(new Uri("pic/rmpng.png", UriKind.RelativeOrAbsolute));
                img.Width = 16.0;
                img.Height = 17.0;
            }
            else if (filetype == ".gif" || filetype == ".GIF")
            {
                img.Source = new BitmapImage(new Uri("pic/rmgif.png", UriKind.RelativeOrAbsolute));
                img.Width = 16.0;
                img.Height = 17.0;
            }
            else if (filetype == "floder")
            {
                img.Source = new BitmapImage(new Uri("pic/rmfloder.png", UriKind.RelativeOrAbsolute));
                img.Width = 16.0;
                img.Height = 15.0;
            }
            grid.Children.Add(img);
            Grid.SetRow(img, 0);
            Grid.SetColumn(img, 0);
            TextBlock name_tb = new TextBlock();
            name_tb.Text = filename;
            name_tb.HorizontalAlignment = HorizontalAlignment.Left;
            name_tb.VerticalAlignment = VerticalAlignment.Center;
            name_tb.TextTrimming = TextTrimming.WordEllipsis;
            grid.Children.Add(name_tb);
            grid.ToolTip = filename;
            Grid.SetRow(name_tb, 0);
            Grid.SetColumn(name_tb, 1);
            fileGrid.Children.Add(grid);
            Grid.SetRow(grid, index);
            Grid.SetColumn(grid,0);
            TextBlock time_tb = new TextBlock();
            time_tb.Text = fileCtime;
            time_tb.HorizontalAlignment = HorizontalAlignment.Right;
            time_tb.VerticalAlignment = VerticalAlignment.Center;
            time_tb.TextTrimming = TextTrimming.WordEllipsis;
            fileGrid.Children.Add(time_tb);
            Grid.SetRow(time_tb, index);
            Grid.SetColumn(time_tb, 2);
            TextBlock size_tb = new TextBlock();
            size_tb.Text = filesize;
            size_tb.HorizontalAlignment = HorizontalAlignment.Right;
            size_tb.VerticalAlignment = VerticalAlignment.Center;
            size_tb.TextTrimming = TextTrimming.WordEllipsis;
            fileGrid.Children.Add(size_tb);
            Grid.SetRow(size_tb, index);
            Grid.SetColumn(size_tb, 4);
            list.Add(img);
            list.Add(name_tb);
            list.Add(time_tb);
            list.Add(size_tb);
            list.Add(grid);
            list_grid.Add(grid);
        }

       
        /// <summary>
        /// 刷新fileGrid
        /// </summary>
        private void ClearFileGrid()
        {
            filelist.Clear();
            ParentList.Clear();
            for (int i = 0; i < list.Count; i++)
            {
                fileGrid.Children.Remove(list[i]);
            }
            list.Clear();
            fileGrid.RowDefinitions.Clear();
            isSel_cb.Items.Clear();

        }
        //选择文件
        void grid_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            for (int i = 0; i < list_grid.Count; i++)
            {
                try {
                    Grid gr = list_grid[i];
                    gr.Background = null;
                }
                catch { }
            }
            Grid rd = (Grid)sender;
           
            //rd.Background = null;
            obj = rd.Tag;
            if (e.ClickCount == 2)
            {
                ClearFileGrid();
                if(rd.Tag is DirectoryInfo)
                {
                    DirectoryInfo di = (DirectoryInfo)rd.Tag;
                    if (type == "image")
                    {
                        GetImageList(di.FullName,"");
                    }
                    else if (type == "computer")
                    {
                        GetComputerList(di.FullName,"");
                    }
                    CreatePreviewObj("", "");
                    GetFileInfor(".文件夹", "", di.FullName, "", di.CreationTime.ToShortDateString(), di.LastWriteTime.ToShortDateString());

                } else if (rd.Tag is FileInfo)
                {
                    FileInfo f = (FileInfo)rd.Tag;
                    App.NewImage = f.FullName;
                    this.Close();
                }
                else if (rd.Tag.ToString() == "rectangle")
                {
                    App.NewRect = "rectangle";
                    this.Close();
                }
               
            }
           //这里添加预览的方法和文件信息的方法
            if (rd.Tag.ToString() == "rectangle")
            {
               
                App.NewRect = "rectangle";
                CreatePreviewObj("",".rectangle");
                GetFileInfor(".矩形","","", "","","");
            }
            else
            if (rd.Tag is FileInfo)
            {
                FileInfo f = (FileInfo)rd.Tag;
                App.NewImage = f.FullName;
                CreatePreviewObj(f.FullName, f.Extension);
                GetFileInfor(f.Extension, ByteConversionGBMBKB(f.Length), f.FullName, "", f.CreationTime.ToShortDateString(), f.LastWriteTime.ToShortDateString());
            }
            else if (rd.Tag is DirectoryInfo)
            {
                App.NewImage = App.NewRect= "";
                DirectoryInfo di = (DirectoryInfo)rd.Tag;
                CreatePreviewObj("", "");
                GetFileInfor(".文件夹", "", di.FullName, "", di.CreationTime.ToShortDateString(), di.LastWriteTime.ToShortDateString());

            }
            rd.Width = 200.0;
            rd.Background = new SolidColorBrush(Color.FromRgb(240, 235, 215));
        }
        /// <summary>
        /// 预览
        /// </summary>
        /// <param name="_url">地址</param>
        /// <param name="_type">类型</param>
        private void CreatePreviewObj(string _url, string _type)
        {
            if (_type == ".jpg" || _type == ".JPG" || _type == ".PNG" || _type == ".png" || _type == ".Gif" || _type == ".gif")
            {
                Image img = new Image();
                img.Stretch = Stretch.Fill;
                img.HorizontalAlignment = HorizontalAlignment.Stretch;
                img.VerticalAlignment = VerticalAlignment.Stretch;
                img.Source = new BitmapImage(new Uri(_url, UriKind.RelativeOrAbsolute));
                preview_border.Child = img;
            }
            else if (_type == ".rectangle")
            {
                Rectangle rect = new Rectangle();
                rect.StrokeThickness = 2;
                rect.Stroke = new SolidColorBrush(Colors.Black);
                rect.Fill = new SolidColorBrush(Colors.Yellow);
                rect.HorizontalAlignment = HorizontalAlignment.Stretch;
                rect.VerticalAlignment = VerticalAlignment.Stretch;
                preview_border.Child = rect;
            }
            else {
                preview_border.Child = null;
            }
        }
        /// <summary>
        /// 文件信息
        /// </summary>
        /// <param name="_filetype">文件类型</param>
        /// <param name="_filesize">文件大小</param>
        /// <param name="_filepath">文件路径</param>
        /// <param name="_filespace">文件占用空间</param>
        /// <param name="_filectime">创建时间</param>
        /// <param name="_fileuptime">修改时间</param>
        private void GetFileInfor(string _filetype,string _filesize,string _filepath,string _filespace,string _filectime,string _fileuptime)
        {
            try
            {
                filetype_txt.Text = _filetype.Substring(1);
            }
            catch {
                filetype_txt.Text = "";
            }
            filesize_txt.Text = _filesize;
            filepath_txt.Text = _filepath;
            filectime_txt.Text = _filectime;
            fileuptime_txt.Text = _fileuptime;
        }



        /// <summary>
        /// 图片文件列表
        /// </summary>
        /// <param name="path"></param>
        private void GetImageList(string path,string Select)
        {
            try
            {
                LastText = ImagePath = path;
                DirectoryInfo dr = new DirectoryInfo(path);
                DirectoryInfo[] dirlist = dr.GetDirectories("*" + Select + "*", SearchOption.TopDirectoryOnly);
                foreach (DirectoryInfo d in dirlist)
                {
                    filelist.Add(d);
                }
                FileInfo[] MyFilelist = dr.GetFiles("*" + Select + "*", SearchOption.TopDirectoryOnly);
                foreach (FileInfo f in MyFilelist)
                {
                    switch (f.Extension.ToLower())
                    {
                        case ".jpg":
                            filelist.Add(f);
                            break;
                        case ".png":
                            filelist.Add(f);
                            break;
                        case ".gif":
                            filelist.Add(f);
                            break;
                    }
                }
                for (int i = 0; i < filelist.Count; i++)
                {
                    if (filelist[i] is FileInfo)
                    {
                        FileInfo f = (FileInfo)filelist[i];
                        CreatFileGrid(i, f.Name, f.CreationTime.ToShortTimeString(), ByteConversionGBMBKB(f.Length), f, f.Extension);
                    }
                    else if (filelist[i] is DirectoryInfo)
                    {
                        DirectoryInfo di = (DirectoryInfo)filelist[i];
                        CreatFileGrid(i, di.Name, di.CreationTime.ToShortTimeString(), "", di, "floder");
                    }
                }
                GetPathParent(path);
                isSel_cb.SelectedItem = isSel_cb.Items[0];
            }
            catch
            {

            }

        }
        /// <summary>
        /// 计算机文件列表
        /// </summary>
        /// <param name="path"></param>
        private void GetComputerList(string path, string Select)
        {
            try
            {
                LastText  = ComputerPath = path;
                DirectoryInfo dr = new DirectoryInfo(path);
                DirectoryInfo[] dirlist = dr.GetDirectories("*" + Select + "*", SearchOption.TopDirectoryOnly);
                foreach (DirectoryInfo d in dirlist)
                {
                    filelist.Add(d);
                }
                FileInfo[] MyFilelist = dr.GetFiles("*" + Select + "*", SearchOption.TopDirectoryOnly);
                foreach (FileInfo f in MyFilelist)
                {
                   filelist.Add(f);
                }
                for (int i = 0; i < filelist.Count; i++)
                {
                    if (filelist[i] is FileInfo)
                    {
                        FileInfo f = (FileInfo)filelist[i];
                        CreatFileGrid(i, f.Name, f.CreationTime.ToShortTimeString(), ByteConversionGBMBKB(f.Length), f, f.Extension);
                    }
                    else if (filelist[i] is DirectoryInfo)
                    {
                        DirectoryInfo di = (DirectoryInfo)filelist[i];
                        CreatFileGrid(i, di.Name, di.CreationTime.ToShortTimeString(), "", di, "floder");
                    }
                }
                GetPathParent(path);
                isSel_cb.SelectedItem = isSel_cb.Items[0];
            }
            catch
            {

            }

        }

        const int GB = 1024 * 1024 * 1024;//定义GB的计算常量
        const int MB = 1024 * 1024;//定义MB的计算常量
        const int KB = 1024;//定义KB的计算常量
        public string ByteConversionGBMBKB(Int64 KSize)
        {
            if (KSize / GB >= 1)//如果当前Byte的值大于等于1GB
                return (Math.Round(KSize / (float)GB, 2)).ToString() + "GB";//将其转换成GB
            else if (KSize / MB >= 1)//如果当前Byte的值大于等于1MB
                return (Math.Round(KSize / (float)MB, 2)).ToString() + "MB";//将其转换成MB
            else if (KSize / KB >= 1)//如果当前Byte的值大于等于1KB
                return (Math.Round(KSize / (float)KB, 2)).ToString() + "KB";//将其转换成KGB
            else
                return KSize.ToString() + "Byte";//显示Byte值
        }

        /// <summary>
        /// 向上
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void upwardBtn_Click(object sender, RoutedEventArgs e)
        {
            ClearFileGrid();
            try
            {
                DirectoryInfo di = new DirectoryInfo(LastText);
                if (type == "image")
                {
                    GetImageList(di.Parent.FullName,"");
                }
                else if (type == "computer")
                {
                    GetComputerList(di.Parent.FullName,"");
                }
                CreatePreviewObj("", "");
                GetFileInfor(".文件夹", "", di.FullName, "", di.CreationTime.ToShortDateString(), di.LastWriteTime.ToShortDateString());
    
            }
            catch 
            {
                string[] Drives;
                Drives = Directory.GetLogicalDrives();

                for (int i = 0; i < Drives.Length; i++)
                {
                    DirectoryInfo di = new DirectoryInfo(Drives[i]);
                    CreatFileGrid(i, Drives[i], "", "", di, "floder");
                    CreatePreviewObj("", "");
                    GetFileInfor(".", "", "", "", "", "");
                }
             }
          
        }

        /// <summary>
        /// 计算机分类
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void computer_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            ClearFileGrid();
            App.NewRect = "";
            upwardBtn.IsEnabled = true;
            type = "computer";
            if (ComputerPath != "")
            {
                GetComputerList(ComputerPath,"");
            }
            else
            {
                string[] Drives;
                Drives = Directory.GetLogicalDrives();

                for (int i = 0; i < Drives.Length; i++)
                {
                    DirectoryInfo di = new DirectoryInfo(Drives[i]);
                    CreatFileGrid(i, Drives[i], "", "", di, "floder");
                    CreatePreviewObj("", "");
                    GetFileInfor(".", "", "", "", "", "");
                }
            }
        }
        /// <summary>
        /// 图片分类
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void image_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
             App.NewRect = "";
             upwardBtn.IsEnabled = true;
             ClearFileGrid();
             type = "image";
             GetImageList(ImagePath,"");
             SaveThePath();
        }
        /// <summary>
        /// 矩形分类
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ListBoxItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            App.NewImage = "";
            upwardBtn.IsEnabled = false;
            ClearFileGrid();
            type = "rectangle";
            CreateRectGrid(0);
            SaveThePath();
        }

        /// <summary>
        /// 确定增加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ok_btn_Click(object sender, RoutedEventArgs e)
        {
            try{
                if (obj != null)
                {
                    ClearFileGrid();
                    SaveThePath();
                    if (obj is DirectoryInfo)
                    {
                        DirectoryInfo di = (DirectoryInfo)obj;
                        if (type == "image")
                        {
                            GetImageList(di.FullName, "");
                        }
                        else if (type == "computer")
                        {
                            GetComputerList(di.FullName, "");
                        }
                        CreatePreviewObj("", "");
                        GetFileInfor(".文件夹", "", di.FullName, "", di.CreationTime.ToShortDateString(), di.LastWriteTime.ToShortDateString());

                    }
                    else if (obj is FileInfo)
                    {
                        FileInfo f = (FileInfo)obj;
                        App.NewImage = f.FullName;
                        this.Close();
                    }
                    else if (obj.ToString() == "rectangle")
                    {
                        App.NewRect = "rectangle";
                        this.Close();
                    }
                }
                else {
                    App.NewRect = null;
                    App.NewImage = null;
                    SaveThePath();
                    this.Close();
                }
            }
            catch
            {
                App.NewRect = null;
                App.NewImage = null;
                SaveThePath();
                this.Close();
            }
        }
        /// <summary>
        /// 取消
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cancel_btn_Click(object sender, RoutedEventArgs e)
        {
            App.NewRect = null;
            App.NewImage = null;
            SaveThePath();
            this.Close();
        }

        /// <summary>
        /// 地址列表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void isSel_cb_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (isSel_cb.SelectedIndex != 0)
            {
                int n = isSel_cb.SelectedIndex;
                if (n >= 0)
                {
                    DirectoryInfo di = (DirectoryInfo)ParentList[n];
                    if (di != null)
                    {
                        ClearFileGrid();
                        if (type == "image")
                        {
                            GetImageList(di.FullName, "");
                        }
                        else if (type == "computer")
                        {
                            GetComputerList(di.FullName, "");
                        }
                        CreatePreviewObj("", "");
                        GetFileInfor(".文件夹", "", di.FullName, "", di.CreationTime.ToShortDateString(), di.LastWriteTime.ToShortDateString());
                    }
                }
            }
        }

        /// <summary>
        /// 搜索历史记录下拉列表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fileSel_cb_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }
        /// <summary>
        /// 搜索按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void sel_btn_Click(object sender, RoutedEventArgs e)
        {
            if (fileSel_cb.SelectedItem == null)
            {
                return;
            }
            DirectoryInfo di = (DirectoryInfo)fileSel_cb.SelectedItem;
            if (di.Exists)
            {
                ClearFileGrid();
                string Select = selfile_txt.Text;

                if (type == "image")
                {
                    GetImageList(di.FullName, Select);
                }
                else if (type == "computer")
                {
                    GetComputerList(di.FullName, Select);
                }

                CreatePreviewObj("", "");
                GetFileInfor(".文件夹", "", di.FullName, "", di.CreationTime.ToShortDateString(), di.LastWriteTime.ToShortDateString());
            }
            else
            {
                ClearFileGrid();
                string Select = selfile_txt.Text;
                if (type == "image")
                {
                    GetImageList(ImagePath, Select);
                }
                else if (type == "computer")
                {
                    GetComputerList(ComputerPath, Select);
                }

                CreatePreviewObj("", "");
                GetFileInfor(".文件夹", "", di.FullName, "", di.CreationTime.ToShortDateString(), di.LastWriteTime.ToShortDateString());

            }
        }

        private void Window_Closed(object sender, EventArgs e)
        {
            SaveThePath();
        }

    }
}

